<ui:composition template="/WEB-INF/templates/layout.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui">
    <ui:define name="content">
        <p:dialog header="#{i18n['label.project.title']}" modal="true" appendTo="@(body)"
                  visible="true" resizable="true" closable="true" widgetVar="dlg_cad_project" 
                  position="center" width="500"
                  >
            <h:form id="form_edit">
                <h:panelGrid columns="3" >
                    <p:outputLabel value="#{i18n['label.project.name']}"/>
                    <p:inputText value="#{projectMB.project.name}" size="40" required="true" requiredMessage="#{i18n['label.project.name.required']}"/>
                    <p:commandButton icon="ui-icon-search"
                                     ajax="true"
                                     actionListener="#{projectMB.loadProjects}"
                                     oncomplete="dlg_list_projects.show()"
                                     update=":form_show"
                                     immediate="true"/>

                </h:panelGrid>
                <h:panelGrid columns="3">
                    <p:commandButton value="#{projectMB.project.id == 0? i18n['label.save'] : i18n['label.update']}"
                                     actionListener="#{projectMB.cadNewProject}"
                                     ajax="false"
                                     process="@form"
                                     update="@form"
                                     icon="#{projectMB.project.id ==0 ? 'ui-icon-disk': 'ui-icon-refresh'}"/>

                    <p:commandButton value="#{i18n['label.clear']}" ajax="true" immediate="true" actionListener="#{projectMB.clear}" update="@form"
                                     icon="ui-icon-cancel"/>

                    <p:commandButton value="#{i18n['label.delete']}" ajax="true" 
                                     actionListener="#{projectMB.remove}" update="@form"
                                     rendered="#{projectMB.project.id != 0}"
                                     icon="ui-icon-trash">
                        <p:confirm header="#{i18n['label.confirmation']}" message="#{i18n['label.message.description']}" icon="ui-icon-alert"/>
                    </p:commandButton>
                </h:panelGrid>

            </h:form>
        </p:dialog>      
        <p:dialog header="#{i18n['label.project.list']}" width="40%" visible="false" 
                  widgetVar="dlg_list_projects" modal="true" appendTo="@(body)"
                  resizable="false"  position="center">
            <h:form id="form_show">
                <p:dataTable var="project" value="#{projectMB.projects}" scrollable="true" id="dt_project"
                             selection="#{projectMB.project}" selectionMode="single" rowKey="#{project.id}">
                    <p:column headerText="#{i18n['label.project.name']}">  
                        <h:outputText value="#{project.name}" />  
                    </p:column>  
                    <f:facet name="footer">  
                        <p:commandButton  value="#{i18n['label.view']}" icon="ui-icon-search" oncomplete="dlg_list_projects.hide();" update=":form_edit"/>  
                    </f:facet>                 
                </p:dataTable>
            </h:form> 
        </p:dialog>
    </ui:define>
</ui:composition>